package com.kaishengit.service;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kaishengit.dao.DocumentDao;
import com.kaishengit.pojo.Document;
import com.kaishengit.pojo.Project;
import com.kaishengit.pojo.User;
import com.kaishengit.util.DateUtil;

@Service
@Transactional
public class DocumentService{
	private DocumentDao documentDao;
	public void save(Document document){
		documentDao.save(document);
	}
	
	public void update(Document document){
		documentDao.update(document);
	}
	
	public void del(int id){
		documentDao.del(id);
	}
	
	public void save(Document document, User user, Project project) {
		document.setCreatetime(DateUtil.getDate());
		document.setUser(user);
		document.setProject(project);
		documentDao.save(document);
	}
	
	public void update(Document document, User user, Project project) {
		document.setCreatetime(DateUtil.getDate());
		document.setUser(user);
		document.setProject(project);
		documentDao.update(document);
		
	}
	
	public Document findById(int id){
		return documentDao.findById(id);
	}
	
	public List<Document> findAll(){
		return documentDao.findAll();
	}
	
	@Autowired
	public void setDocumentDao(DocumentDao documentDao) {
		this.documentDao = documentDao;
	}

	public List<Document> findByProjectId(Project project) {
		
		return documentDao.findByProjectId(project);
	}

	

}
